package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * Created by Administrator on 2017/6/30.
 */
public class Main {
    public static void main(String[] args) {
        //线程池
        ExecutorService es = Executors.newSingleThreadExecutor();
        //创建任务对象
        CallableTest callableTest = new CallableTest();
        //提交任务并获得返回值
//        Future<Integer> future = es.submit(callableTest);
        FutureTask<Integer> future = new FutureTask<Integer>(callableTest);
        es.submit(future);
        //关闭线程池
        es.shutdown();
    try{
    Thread.sleep(2000);
    System.out.println("主线程在执行其他任务");
    if(future.get()!=null){
            //输出获取到的结果
            System.out.println("future.get()-->"+future.get());
        }else{
            //输出获取到的结果
            System.out.println("future.get()未获取到结果");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
        System.out.println("主线程在执行完成");

}
}
